#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2017-06-27 09:40:34
# @Author  : Your Name (you@example.org)
# @Link    : http://example.org
# @Version : $Id$

import psycopg2

try:
    conn = psycopg2.connect("dbname='testdb' user='postgres' host='localhost' password='0000'")

    cur = conn.cursor()

    cur.execute("""SELECT (id,name) FROM testdb.testtb;""")# select property from table
    rows = cur.fetchall()
    for row in rows:
        print row[0]

    cur.execute("""INSERT INTO testdb.testtb (id,name) VALUES (%s,%s);""",(6,"n6"))
    conn.commit() # insert confirm

    conn.close()

except Exception as e:
    print e